include ../makedef.mk
INC := -I../include/ -I../include_api/ -I../include_arch/ -I../include_plat/

test_files := $(wildcard ./build/g*.o)
test_target := $(patsubst %.o,%.o,${test_files})

test_files_cocomi := $(wildcard ./build/gcocomi*.o)
test_target_cocomi := $(patsubst %.o,%.o,${test_files_cocomi})

test_files_cocoro := $(wildcard ./build/gcocoro*.o)
test_target_cocoro := $(patsubst %.o,%.o,${test_files_cocoro})

cur_path := $(shell pwd)
perf := 
#/usr/bin/time -v 
# INC := ${INC} -I./libco -I./src
# LIBS := ${LIBS}
# LIBS_CO := ${LIBS} ./libco/solib/libcolib.so 

GCCFLAGS := ${GCCFLAGS} ${GCCANALYZER} -Wno-error=analyzer-possible-null-dereference \
			-Wno-error=analyzer-malloc-leak -Wno-error=analyzer-null-dereference \
			-Wno-error=analyzer-possible-null-argument

# fix mac
ifeq ($(uname_s),Darwin)
	GCCFLAGS := 
endif

.PHONY:clean test all

all:$(target)
	@rm -f *.plist

lib:
	@make clean -C ./src
	@make -C ./src

clean:
	rm -f ./build/*.o 

test:$(test_target)

g%.o:cl%.o
	${perf} ./$@
	${perf} ./$<

regre:$(test_target_cocomi) $(test_target_cocoro)


%.o:%.c
	@mkdir -p ./build
	@echo "----run clang static analyzer----"
	@${CLANG} ${INC} ${PREDEFINED} -I./src -DCOCO --analyze $^
	@echo "----compiling using gcc with analyzer for libcoco ----"
ifeq ($(uname_m),x86_64)
	@${GCC} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/glibcoco_aco.${sharelib} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -DCOCO -o ./build/gaco$@
endif
	@${GCC} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/glibcoco_concurrent.${sharelib} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -DCOCO -o ./build/gconcurrent$@
ifneq ($(uname_s),Darwin)
	@${GCC} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/glibcoco_coroutine.${sharelib} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -DCOCO -o ./build/gcoroutine$@
endif
	@${GCC} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/glibcoco_mprompt.${sharelib} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -DCOCO -o ./build/gmprompt$@
	@${GCC} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/glibcoco_cocoro.${sharelib} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -DCOCO -o ./build/gcocoro$@
	@${GCC} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/glibcoco_cocomi.${sharelib} ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -DCOCO -o ./build/gcocomi$@
	@echo "----compiling using clang with libcocoro ----"
ifeq ($(uname_m),x86_64)
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/cllibcoco_aco.${sharelib} ${COPT_FLAGS} ${CFLAGS} -DCOCO -o ./build/claco$@
endif
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/cllibcoco_concurrent.${sharelib} ${COPT_FLAGS} ${CFLAGS} -DCOCO -o ./build/clconcurrent$@
ifneq ($(uname_s),Darwin)
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/cllibcoco_coroutine.${sharelib} ${COPT_FLAGS} ${CFLAGS} -DCOCO -o ./build/clcoroutine$@
endif
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/cllibcoco_mprompt.${sharelib} ${COPT_FLAGS} ${CFLAGS} -DCOCO -o ./build/clmprompt$@
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/cllibcoco_cocoro.${sharelib} ${COPT_FLAGS} ${CFLAGS} -DCOCO -o ./build/clcocoro$@
	@${CLANG} ${INC} ${PREDEFINED} $^ ${LIBS} ${cur_path}/build_libso/cllibcoco_cocomi.${sharelib} ${COPT_FLAGS} ${CFLAGS} -DCOCO -o ./build/clcocomi$@
ifeq ($(uname_m),x86_64)
	@echo "----compiling using g++ with libco----"
	@g++ ${INC} ${PREDEFINED} -I./git3rd/libco $^ ${LIBS} ${cur_path}/git3rd/libco/solib/libcolib.so ${COPT_FLAGS} -DLIBCO  -o ./build/glibco$@
	@g++ ${INC} ${PREDEFINED} -I./git3rd/libco $^ ${LIBS} ${cur_path}/git3rd/libco/solib/libcolib.so ${COPT_FLAGS} -DLIBCO  -o ./build/cllibco$@
	# @#echo "----compiling using clang++ with libco----"
	# @${CLANG}++ ${INC} ${PREDEFINED} -I./libco $^ ${LIBS} ${cur_path}/git3rd/libco/solib/libcolib.so ${COPT_FLAGS} -DLIBCO -Wno-deprecated -o cllibco$@
endif